package exp.parser;

import grammar.parser.FuncFParams;
import grammar.parser.GrammarParser;
import semantic.parser.SemanticParser;

import java.util.ArrayList;
import java.util.List;

public abstract class ExpParser extends GrammarParser {
    private boolean isComputable;
    private final boolean isConst;
    private Integer value = null;
    private boolean hasCompute = false;

    private static boolean forceComputable = false;

    public ExpParser(boolean isComputable, boolean isConst) {
        this.isComputable = isComputable;
        this.isConst = isConst;
    }

    public static void initBeforeExecute() {
        forceComputable = true;
    }

    public final Integer getValue() {
        if (isComputable || forceComputable) {
            value = this.compute();
        }
        return value;
    }


    public boolean isConst() {
        return isConst;
    }

    public abstract LVal toLVal();

    public abstract Integer compute();

    public abstract FuncFParams.FuncFParam checkDimension();

    public boolean isComputable() {
        return isComputable || forceComputable;
    }

    public List<List<Integer>> getValueAsParam() {
        List<List<Integer>> ans = new ArrayList<>();
        ans.add(new ArrayList<>());
        ans.get(0).add(this.getValue());
        return ans;
    }
}
